from django.shortcuts import render
from django.http import HttpResponse
from app.utils.forms import AddForm

# Create your views here.


def home(req):
    string = "this just is a test"
    tutorial_list = ["HTML", "CSS", "jQuery", "Python", "Django"]
    info_dict = {'site': u'自强学堂', 'content': u'各种IT技术教程'}
    return render(req, "app/index.html", {"string": string, "tutorial_list": tutorial_list, "info_dict": info_dict})


def add(req):
    if req.method == "POST":
        print(req.POST)
        form = AddForm(req.POST)
        if form.is_valid():
            a = form.cleaned_data['a']
            b = form.cleaned_data['b']
            return HttpResponse(str(int(a) + int(b)))

    else:
        return render(req, "app/forms.html", {"form": AddForm()})
